package com.spa.application.service.admin;

import com.spa.application.dto.PageResult;
import com.spa.application.dto.admin.CouponDTO;
import com.spa.application.dto.admin.CouponExchangeDTO;
import com.spa.application.dto.admin.CouponExchangeExportDTO;
import com.spa.application.dto.admin.CouponExportDTO;
import com.spa.application.query.admin.AdminCouponExchangeQuery;
import com.spa.application.query.admin.AdminCouponQuery;
import com.spa.domain.service.CouponExchangeService;
import com.spa.domain.service.CouponService;
import com.spa.infrastructure.mapper.CouponMapperStruct;
import com.spa.infrastructure.repository.condition.CouponCondition;
import com.spa.infrastructure.repository.condition.CouponExchangeCondition;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class AdminCouponApplicationService {

    @Autowired
    private CouponExchangeService couponExchangeService;

    @Autowired
    private CouponService couponService;

    public PageResult<CouponExchangeDTO> page(AdminCouponExchangeQuery query) {
        CouponExchangeCondition condition = CouponMapperStruct.INSTANCE.query2Condition(query);
        condition.setDestroyTimeDesc(true);
        return CouponMapperStruct.INSTANCE.entity2CouponExchangeDTO4Page(couponExchangeService.page(condition));
    }

    public List<CouponExchangeExportDTO> list(AdminCouponExchangeQuery query) {
        CouponExchangeCondition condition = CouponMapperStruct.INSTANCE.query2Condition(query);
        condition.setDestroyTimeDesc(true);
        return CouponMapperStruct.INSTANCE.entity2CouponExchangeDTO4List(couponExchangeService.list(condition));
    }

    public PageResult<CouponDTO> pageCoupon(AdminCouponQuery query) {
        CouponCondition condition = CouponMapperStruct.INSTANCE.query2Condition(query);
        condition.setUseTimeDesc(true);
        condition.setStatus(1);
        return CouponMapperStruct.INSTANCE.entity2CouponDTO4Page(couponService.page(condition));
    }

    public List<CouponExportDTO> listCoupon(AdminCouponQuery query) {
        CouponCondition condition = CouponMapperStruct.INSTANCE.query2Condition(query);
        condition.setUseTimeDesc(true);
        condition.setStatus(1);
        return CouponMapperStruct.INSTANCE.entity2CouponDTO4List(couponService.list(condition));
    }

}
